// 引入常量
import { INCREMENT, DECREMENT, CHANGE_COUNT } from "../actionTypes";

const defaultState = {
  msg: "~",
  count: 0,
};

export default function rootReducer(state = defaultState, action) {
  console.log("payload", action.payload);

  switch (action.type) {
    case INCREMENT:
      return {
        ...state,
        count: state.count + 1,
      };
    case DECREMENT:
      return {
        ...state,
        count: state.count - 1,
      };

    case CHANGE_COUNT:
      return {
        ...state,
        count: action.payload,
      };

    default:
      return state;
  }
}
